/*
day261
2020.5.15  
*/
#include<cstdlib> 
#include<string>
#include<algorithm>
#include<set>
#include<vector> 
#include<iostream>
using namespace std;
struct TreeNode {
    int val;
    TreeNode *left;
    TreeNode *right;
    TreeNode(int x) : val(x), left(NULL), right(NULL) {}
};

class Solution {
public:
    string smallestFromLeaf(TreeNode* root) {
        if(!root)
        {
        	return "";
		}
		
        vector<string> vec=help(root);
        
        sort(vec.begin(),vec.end());
        
        return vec.back();
    }
    
    
    
    vector<string> help(TreeNode *root)
    {
    	vector<string> res;
    	char cur='a'+root->val;
    	
    	if(!root->left && !root->right)
    	{
    		res.push_back(""+cur);
		}
		
		
		vector<string> tem;
		if(root->left)
		{
			tem=help(root->left);
			for(int i=0;i<tem.size();++i)
			{
				res.push_back(tem[i]+cur);
			 } 
		}
		
		if(root->right)
		{
			tem=help(root->right);
			for(int i=0;i<tem.size();++i)
			{
				res.push_back(tem[i]+cur);
			 } 
		}
		
		
		return res;
	}
    
};

int main()
{
	return 0;
}
